Fixed a major bug regarding directions and many small progresses