modified signed integer stuff, changed logic in complex version