Author: Simon Anders updated code