updated source code of Lab8 with some improvements and simplifications