checks parameter validity and general cleanup