move error classes to separate file

Also removed superfluous .to_int usage