Added description to functions and added some error handling