needs refactoring - but for the time being it works