Robotic Joint-Motion Optimization of Functionally-Redundant Tasks: With Application on Joint-Limits and Singularity Avoidance