added some code improvements (optimization)
added some code optimizations