Fixed most bugs from Aidan's changes