Cleaned up jQuery function