Modifications based on ptizef's changes