made changes to work with slam - but crashing when not run in gdb mode - and not sure if it works when not crashing