reorganized code
fixed angled edges