big code purge

@mmalecki comments welcome.