fixed bug with aligning matrices. All functions work properly now