new version with a couple bugs fixed