improved but still buggy
improved buggy version