final code from solution