various bugfixes, still doesn't pass the tests though.
fixed all bugs. It passes the tests now