added handling for special prime cases 1 and 2