Fixed various bugs #3