Performance tweaks and better error handling

Also not including safetyvalve as a dep, thus reducing deps substantially