Cleaned up a bit, combined two small functions