Code optimization

Some parts of code were been optimized and also fixed secure issue. Closes #34