improved print function