refactored render to a function (rather than object)