Cleaned some code and more "pythonic" way to handle POST dict