fixed most bugs and added paranoid assertions