Code clean up and bug fixes

Signed-off-by: Ozan Turgut <ozanturgut@gmail.com>