Debugged. Verified working. Test case passes! :)