fixed issue #309

Fixed issue #309 by adding the solution of @FelixLin