Refactoed
part 2 added