cleaning things up a bit, trying to DRY up code and organize things better. Introduced some bugs here...