Fixed various bugs, test now passes!