Needs testing, got rid of some other bugs