modified to work with Flask