fixing up code refactoring, defining assert