Code clean up and improvement