Fixed all bugs. Should work correctly now