Removed redundant code and simplified.