Rebased from django to flask :)