Fixed bug, seems to be working