changed entity-repository into a class, renamed %finalize to finalize
reorganzied code