Refactoring lab 1. Some improvements in algotithm. Start Lab 2.