replace long chain of ifs with some elifs and add 404 exception