Final, tested version, with header