Fixed issues #88, #145, #146 and #147