Simplified and removed redundant code