Fixes multiple bug with current implementation.

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