Code Makeover and minor bug fix