Code clean up and improvments