improve rectangular code