put into class and cleaned up. TODO: get start id