updated test cases and modularized code