code beautifying and minor bug fixes