Use STDOUT instead of STDIN

not that it seems to matter.

And use macros instead of heap