More tests added and refactor