cleaned up code to sync with book