Refactor done as per ruby style guide