Added header and minor bug fixes