Cleaned up code and now working 100%