Add checks and tests

Sorry it's also a big PR