part of tutorial4 but with some errors