Added error handling and some templates