Fixing it up a little bit here. Untested