Minor improvements. Code still buggy.