initial solution - imperative style