Fixed bugs

Fixed some bugs with earlier commit