Fixed order issues

Added array empty handling.
Added error handling

Fixed array list bugs