Fixed various bugs introduced in the last commit