cloned from https://gitorious.org/nahanni/