add permalink, more code cleanup