Cleaned up code, made it more generic and added info to README