Second version with major improvements