most of task4 implemented