Lots of bugfixes and range checks working