improved version, compiles and executes