Updated code

Seems to work a little better now