Refactored to implement checks on post data input and throw exceptions.