Modified order/syntax, cleaned up functions.