Restructure, perfect square check