merged jake's changes and fixed some small issues