Some code changes, kill 2 birds with 1 stone.

Signed-off-by: crynobone <crynobone@gmail.com>