Fixed some const issues with the code. Now there is a memory leak somewhere