Updated copyrights and slightly refactored the code