fixed sign extension bug, see https://gist.github.com/shuttler/5916727