Improved code for online exercises

part 1