re-worked code