refactored and consolidated for ease of reading

works identically to live version. unfortunately, -prevTrack still
refuses to operate as expected (few attempts left)