A3 - Completed Cost Function