fixed some bugs, cleaned things up

Signed-off-by: Daniel Fagnan <dnfagnan@gmail.com>