more code improvements and made it easier to add other backends