fixed undefined behavior and updated Makefile