First running version of reworked code