Code cleanup, moved to modules where logically belongs