fix bugs and add changes from zappala