workable code from Lab3