Bug fixes

Fixing #304 , #291 , #77 , #315