Added padding.
Added output handling and memory allocation.