Refactoring + Efficiency

I've made cosmetic changes as well as performance improvement.