Added memory management to input.
Cleaned up slightly.