Fixed issue caused by inputs with single-direction content only.
Removed duplicate codes.
A lot of code cleanup and organization.
:)