updated complete solution