Cleaned up a little (not tested)