Changed the code layout a bit, seems to work fine at this point.