basic logic and formatting complete