Merged all code and added more tests