Code refactor part I [unused code parts moved]