Complete rewrite of Leonardo to be more extensible and faster