code optimization and layout fix