moved post processing code to a separate function