General cleanup - refactor to match the book