main body completed, lots a edge case still to handle