Fixed various bugs with the code. 36/155 still fails