impoved with mostly external code, well done