removed global db
abstracted logic into object
revamped tests to handle code object and db