Messy bug fixes, will take out print statements.