merged Mark's code