clean up code and use pytest fixtures