better error handling and using specific variable types instead of int

Signed-off-by: Tal Kain <tal.kain@ravellosystems.com>