working version of ex4_1; should be improved