Big changes

Added more robust checking of submitted data and handling of other edge
cases