Optimize code structure, TODO: with database.