Finalized code

Code finalized, test cases added.