various bug fixes, still buggy