Fixed invoice error handling & code cleanup

Fixed deprecated uses of the old PHP4-style var keyword