refactored code to use peewee orm