Fixed bugs

Fixed two bugs and added new functionality