Moved some code out of cloudcode and into the app. Cloud code sucks.