Added a sanity check, removed dead code, used primitive type (instead of boxing)