Refactored & tested. need to test for different buidl flags.