Updated corner region calculation

Updated corner region calculation to take margins into account. Still is
not completely working