Added top and bottom functions as well as proper deletions based on queries.