sorted out issues thanks to Bugsduggan and gdb