This function can be implemented better.