Reviewed code : Fixed TODOs, added error-checking code