Implement region detection better