Cleaned up the code and brought it back to life. It still needs tests and further refinements
Added missing libraries