betsys-core code refactoring