end of ch 4, fixing bugs. utility functions missing