added check if finished and refactored last number
merged