Fixed bugs, got rid of some suspicious printf calls