Several Bugfixes

Signed-off-by: Soroush Rabiei <soroush.rabiei@gmail.com>