re-structured code, made nicer header