Straight from gomspace's code. Didn't want to edit any of it.