modularized code
added test cases