Fixed profiler code using SQLAlchemy

Please review and let me know if you think anything should be changed.