Ugly code need to comment and re-org