Added more test and cleaned up code reducing line numbers