Fixed most of the remaining problems, added prolog/epilog