first version after merging stage 1 and 2