Updated code, not tested