WIP performance
WIP performance, porting some code from lua to cpp