Refactored 50 and added test cases.