-rearranged code
-fixed smaller errors
-optimized code