Changed the code from an (nonworking) experimental version