Code clean up and Unit testing