Major refactoring: moved most of the functionality into a class

Refactored functionality into class "Obligator" to improve overall clarity. Arguments such as session=session are now self.session.