Fixed various problems with previous commit