Simplified version of the code + some class fixing