Some stuff from daboross' fork