code clean up, fix views, add error template