Changed tests cases and some refactoring