Code rewrite part 1