Fixing infinite loop bug, improving build