optimized, removed redundant code