Completed code and validation