Fixed test case & refactoring

Travis will be green. Will push up to master once reviewed.