Adding in lahiff's improvements