Little refactoring and code beautified