Added a zero-variable check and cleaned up code