Unit testing and small code clean up