Refactor to fulfil Promise/A+ spec