Initial code, seperated from the site it was built for, needs a tidy up