Cleaned it up a bit and added function prototype