better error messages, split functions into separate modules