adds validation and correct swift error handling