code clean up, added test covrage