optimizated some code and removed redundant code