Add comments, fix function name, handle empty inputs