Cleaned up a bit by pulling out common methods