First version of implemented code (not tested)