Copied over refactored logic classed from eclipse project to ensure integrity.