Fixed Bugs

Properly working version