Fixed warnings and unusual casts
Applied proposal to fix #2