now handles out of memory exceptions
fixing small parentheses error
fixing memory leak