Added security. Did some refactory