Fixed Bugs, and added shape detection for testing purpose