cleaned up code, had problems with callback function