Added test cases
Added test cases and moved code into lib