Added separate tests and reorganized code