changing order of checks, other minor bugfixes