Minor fixes, still needs debugging